#!/bin/bash

if [ -n "$1" ] ; then
  data_date=$1
else
  data_date=`date -d "-1 days" +%F`
fi

ODS_PRODUCT_LOG="
LOAD DATA INPATH '/warehouse/product_basic/ods_product_log/${data_date}'
OVERWRITE INTO TABLE product_warehouse.ods_product_log PARTITION (dt='${data_date}');
"

ODS_PRODUCT_ORDER="
LOAD DATA INPATH '/warehouse/product_basic/ods_product_order/${data_date}'
OVERWRITE INTO TABLE product_warehouse.ods_product_order PARTITION (dt ='${data_date}');
"

ODS_ORDER_DETAIL="
LOAD DATA INPATH '/warehouse/product_basic/ods_order_detail/${data_date}'
OVERWRITE INTO TABLE product_warehouse.ods_order_detail PARTITION (dt ='${data_date}');
"

ODS_USER_INFO="
LOAD DATA INPATH '/warehouse/product_basic/ods_user_info/${data_date}'
OVERWRITE INTO TABLE product_warehouse.ods_user_info PARTITION (dt ='${data_date}');
"

ODS_PRODUCT_CATEGORY="
LOAD DATA INPATH '/warehouse/product_basic/ods_product_category/${data_date}'
OVERWRITE INTO TABLE product_warehouse.ods_product_category PARTITION (dt ='${data_date}');
"

ODS_PRODUCT_BRAND="
LOAD DATA INPATH '/warehouse/product_basic/ods_product_brand/${data_date}'
OVERWRITE INTO TABLE product_warehouse.ods_product_brand PARTITION (dt ='${data_date}');
"

ODS_PRODUCT_REVIEW="
LOAD DATA INPATH '/warehouse/product_basic/ods_product_review/${data_date}'
OVERWRITE INTO TABLE product_warehouse.ods_product_review PARTITION (dt ='${data_date}');
"

ODS_PAYMENT_METHOD="
LOAD DATA INPATH '/warehouse/product_basic/ods_payment_method/${data_date}'
OVERWRITE INTO TABLE product_warehouse.ods_payment_method PARTITION (dt ='${data_date}');
"

/opt/module/spark/bin/beeline -u jdbc:hive2://node101:10001 -n bwie -e "${ODS_PRODUCT_LOG}
${ODS_PRODUCT_ORDER}${ODS_ORDER_DETAIL}${ODS_USER_INFO}${ODS_PRODUCT_CATEGORY}${ODS_PRODUCT_BRAND}${ODS_PRODUCT_REVIEW}${ODS_PAYMENT_METHOD}"